package org.itboys.basetemplate.service;

import org.itboys.admin.entity.BusinessCenter;
import org.itboys.admin.service.BusinessCenterService;
import org.itboys.baseobject.entity.C;
import org.itboys.basetemplate.entity.IncomeRecord;
import org.itboys.member.entity.Member;
import org.itboys.member.service.MemberService;
import org.itboys.mongodb.core.MongoDataSource;
import org.itboys.mongodb.service.BaseService;
import org.itboys.seller.entity.Seller;
import org.itboys.seller.service.SellerService;
import org.itboys.trade.constant.OrderConstant;
import org.itboys.trade.entity.Order;
import org.itboys.trade.entity.OrderItem;
import org.itboys.trade.entity.TicketOrder;
import org.itboys.trade.entity.TicketOrderItem;
import org.itboys.trade.entity.mysql.AdminAmountRecord;
import org.itboys.trade.entity.mysql.UserWithdrawRecord;
import org.itboys.trade.service.OrderItemService;
import org.itboys.trade.service.OrderService;
import org.itboys.trade.service.TicketOrderItemService;
import org.itboys.trade.service.TicketOrderService;
import org.itboys.trade.service.mysql.AdminAmountRecordService;
import org.itboys.trade.service.mysql.UserWithdrawRecordService;
import org.itboys.weixin.entity.CommissionConfig;
import org.itboys.weixin.service.CommissionConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;

/**
 * 收益详情
 *
 * @author weisky
 */
@Service
public class IncomeRecordService extends BaseService<IncomeRecord, Long> {

    private static final long serialVersionUID = 1L;

    @Resource
    private CommissionConfigService commissionConfigService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private MemberService memberService;
    @Autowired
    private BusinessCenterService businessCenterService;
    @Autowired
    private SellerService sellerService;
    @Autowired
    private OrderItemService orderItemService;
    @Autowired
    private TicketOrderService ticketOrderService;
    @Autowired
    protected TicketOrderItemService ticketOrderItemService;
    @Autowired
    private UserWithdrawRecordService withdrawRecordService;
    @Autowired
    private AdminAmountRecordService adminRecordService;
    @Resource(name = "adminDS")
    private MongoDataSource ds;

    @Override
    protected MongoDataSource getMongoDataSource() {
        return ds;
    }
    
    /**
     * 开始分各种收益
     *
     * @param orderId ：订单ID
     */
    public void startIncome(Long orderId) {
        // 获取分红百分比
        CommissionConfig commission = commissionConfigService.getConfig();
        double adminSc = commission.getAdminLevel(); //总平台佣金
        double sellerSc = commission.getSellerLevel(); // 店铺佣金
        double centerSc = commission.getCenterLevel(); // 运营中心佣金
        double oneSc = commission.getFirstLevel(); // 一级会员佣金
        double twoSc = commission.getSecondLevel(); // 二级会员佣金
        double threeSc = commission.getThirdLevel(); // 三级会员佣金
        double moreSc = 1 - commission.getAdminLevel() - commission.getSellerLevel() - commission.getCenterLevel() - commission.getFirstLevel() - commission.getThirdLevel() - commission.getSecondLevel();
        Order order = orderService.getById(orderId);
        adminRecordService.insert(new AdminAmountRecord(order.getCenterId(), 
        		AdminAmountRecord.objType_center,
        		AdminAmountRecord.tradeType_order, 
        		Double.valueOf(order.getWithAmount()), 
        		0d,
        		order.getId(), 
        		OrderConstant.orderType_pro,
        		Double.valueOf(order.getTotalMoney()), 
        		Double.valueOf(order.getTotalMoney()-order.getWithAmount())));
        Member member = memberService.getById(order.getMemberId());
        Seller seller = sellerService.getById(member.getSellerId());
        BusinessCenter center = businessCenterService.getById(member.getCenterId());

        DecimalFormat df = new DecimalFormat("0.00");
        Integer totalScale=0;
        List<OrderItem> orderItems = orderItemService.findByField("orderId", orderId);
        for (OrderItem oi : orderItems) {
            if (oi.getScale() == 0) {
                continue;
            } else {
            	totalScale+=oi.getScale()* oi.getNum();
            }
        }
        if (totalScale>0) {
                //Double totalScale = oi.getScale() * oi.getNum() / 100.0;
                BigDecimal adminMoney = new BigDecimal(totalScale * adminSc);// 平台佣金
                BigDecimal centerMoney = new BigDecimal(totalScale * centerSc);// 运营中心佣金
                BigDecimal sellerMoney = new BigDecimal(totalScale * sellerSc);// 店铺佣金
                BigDecimal oneMoney = new BigDecimal(totalScale * oneSc);// 一级提成
                BigDecimal twoMoney = new BigDecimal(totalScale * twoSc);// 二级提成
                BigDecimal threeMoney = new BigDecimal(totalScale * threeSc);// 三级提成
                BigDecimal moreMoney = new BigDecimal(totalScale * moreSc);// 没分完
                String[] paths = member.getPath().split("/");// 会员路径的分割
                if (member.getType() == 3) {// 店铺发展的下线
                    // 平台的提成
                    IncomeRecord incomeRecordShop = new IncomeRecord();
                    incomeRecordShop.setObjId(orderId);
                    incomeRecordShop.setObjType(1);
                    incomeRecordShop.setType(1);
                    incomeRecordShop.setAmount(Double.parseDouble(df.format(adminMoney.doubleValue())));
                    incomeRecordShop.setMoney(Double.parseDouble(df.format(adminMoney.doubleValue())));
                    incomeRecordShop.setUserId(0L);// 分红的获得者
                    incomeRecordShop.setFromUserId(member.getId());
                    incomeRecordShop.setCreateTime(new Date());
                    save(incomeRecordShop);
                    
                    AdminAmountRecord record=new AdminAmountRecord(0l, 
                    		AdminAmountRecord.objType_admin,
                    		AdminAmountRecord.tradeType_commission, 
                    		adminMoney.doubleValue(), 
                    		0d,
                    		orderId, 
                    		OrderConstant.orderType_pro,
                    		Double.valueOf(order.getTotalMoney()), 
                    		Double.valueOf(totalScale));
                    adminRecordService.insert(record);
                    //运营中心的提成
                    IncomeRecord incomeRecordShopAchie = new IncomeRecord();
                    incomeRecordShopAchie.setObjId(orderId);
                    incomeRecordShopAchie.setObjType(1);
                    incomeRecordShopAchie.setType(1);
                    incomeRecordShopAchie.setAmount(Double.parseDouble(df.format(centerMoney.doubleValue())));
                    incomeRecordShopAchie.setMoney(Double.parseDouble(df.format(centerMoney.doubleValue())));
                    incomeRecordShopAchie.setUserId(center.getSelfMemberId());// 分红的获得者
                    incomeRecordShopAchie.setFromUserId(member.getId());
                    incomeRecordShopAchie.setCreateTime(new Date());
                    save(incomeRecordShopAchie);
                    adminRecordService.insert(new AdminAmountRecord(member.getCenterId(), 
                    		AdminAmountRecord.objType_center,
                    		AdminAmountRecord.tradeType_commission, 
                    		centerMoney.doubleValue(), 
                    		0d,
                    		orderId, 
                    		OrderConstant.orderType_pro,
                    		Double.valueOf(order.getTotalMoney()), 
                    		Double.valueOf(totalScale)));
                    //店铺的提成
                    IncomeRecord incomeRecordCha = new IncomeRecord();
                    incomeRecordCha.setObjId(orderId);
                    incomeRecordCha.setObjType(1);
                    incomeRecordCha.setType(1);
                    incomeRecordCha.setAmount(Double.parseDouble(df.format(sellerMoney.doubleValue())));
                    incomeRecordCha.setMoney(Double.parseDouble(df.format(sellerMoney.doubleValue())));
                    incomeRecordCha.setUserId(seller.getSelfMemberId());// 分红的获得者
                    incomeRecordCha.setFromUserId(member.getId());
                    incomeRecordCha.setCreateTime(new Date());
                    save(incomeRecordCha);
                    adminRecordService.insert(new AdminAmountRecord(member.getSellerId(), 
                    		AdminAmountRecord.objType_seller,
                    		AdminAmountRecord.tradeType_commission, 
                    		centerMoney.doubleValue(), 
                    		0d,
                    		orderId, 
                    		OrderConstant.orderType_pro,
                    		Double.valueOf(order.getTotalMoney()), 
                    		Double.valueOf(totalScale)));
                    if (paths.length == 5) {
                        // 判断是否成为分销商
                        Member member1 = memberService.getById(Long.valueOf(paths[3]));
                        if (member1.getIsView() == 1) {
                            IncomeRecord incomeRecordMember1 = new IncomeRecord();
                            incomeRecordMember1.setObjId(orderId);// 设置订单ID
                            incomeRecordMember1.setObjType(1);// 收益类型是会员分红
                            incomeRecordMember1.setType(1);
                            incomeRecordMember1.setAmount(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember1.setMoney(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember1.setUserId(member1.getId());
                            incomeRecordMember1.setFromUserId(member.getId());
                            incomeRecordMember1.setCreateTime(new Date());
                            save(incomeRecordMember1);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		member1.getId(),
                            		Double.parseDouble(df.format(oneMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_pro));
                            moreMoney = moreMoney.add(twoMoney).add(threeMoney);
                        } else {
                            moreMoney = moreMoney.add(oneMoney).add(twoMoney).add(threeMoney);
                        }
                    } else if (paths.length == 6) {
                        // 判断是否成为分销商
                        Member member1 = memberService.getById(Long.valueOf(paths[3]));
                        if (member1.getIsView() == 1) {
                            IncomeRecord incomeRecordMember1 = new IncomeRecord();
                            incomeRecordMember1.setObjId(orderId);// 设置订单ID
                            incomeRecordMember1.setObjType(1);// 收益类型是会员分红
                            incomeRecordMember1.setType(1);
                            incomeRecordMember1.setAmount(Double.parseDouble(df.format(twoMoney.doubleValue())));
                            incomeRecordMember1.setMoney(Double.parseDouble(df.format(twoMoney.doubleValue())));
                            incomeRecordMember1.setUserId(member1.getId());
                            incomeRecordMember1.setFromUserId(member.getId());
                            incomeRecordMember1.setCreateTime(new Date());
                           
                            save(incomeRecordMember1);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		member1.getId(),
                            		Double.parseDouble(df.format(twoMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_pro));
                        } else {
                            moreMoney = moreMoney.add(twoMoney);
                        }

                        // 判断是否成为分销商
                        Member member2 = memberService.getById(Long.valueOf(paths[4]));
                        if (member2.getIsView() == 1) {
                            IncomeRecord incomeRecordMember2 = new IncomeRecord();
                            incomeRecordMember2.setObjId(orderId);// 设置订单ID
                            incomeRecordMember2.setObjType(1);// 收益类型是会员分红
                            incomeRecordMember2.setType(1);
                            incomeRecordMember2.setAmount(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember2.setMoney(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember2.setUserId(member2.getId());
                            incomeRecordMember2.setFromUserId(member.getId());
                            incomeRecordMember2.setCreateTime(new Date());
                            save(incomeRecordMember2);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		member2.getId(),
                            		Double.parseDouble(df.format(oneMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_pro));
                        } else {
                            moreMoney = moreMoney.add(oneMoney);
                        }
                        moreMoney = moreMoney.add(threeMoney);
                    } else if (paths.length > 6) {
                        Long one = Long.valueOf(paths[paths.length - 2]);
                        Long two = Long.valueOf(paths[paths.length - 3]);
                        Long three = Long.valueOf(paths[paths.length - 4]);
                        // 判断是否成为分销商
                        Member member1 = memberService.getById(three);
                        if (member1.getIsView() == 1) {
                            IncomeRecord incomeRecordMember1 = new IncomeRecord();
                            incomeRecordMember1.setObjId(orderId);// 设置订单ID
                            incomeRecordMember1.setObjType(1);// 收益类型是会员分红
                            incomeRecordMember1.setType(1);
                            incomeRecordMember1.setAmount(Double.parseDouble(df.format(threeMoney.doubleValue())));
                            incomeRecordMember1.setMoney(Double.parseDouble(df.format(threeMoney.doubleValue())));
                            incomeRecordMember1.setUserId(three);
                            incomeRecordMember1.setFromUserId(member.getId());
                            incomeRecordMember1.setCreateTime(new Date());
                            save(incomeRecordMember1);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		three,
                            		Double.parseDouble(df.format(threeMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_pro));
                        } else {
                            moreMoney = moreMoney.add(threeMoney);
                        }

                        // 判断是否成为分销商
                        Member member2 = memberService.getById(two);
                        if (member2.getIsView() == 1) {
                            IncomeRecord incomeRecordMember2 = new IncomeRecord();
                            incomeRecordMember2.setObjId(orderId);// 设置订单ID
                            incomeRecordMember2.setObjType(1);// 收益类型是会员分红
                            incomeRecordMember2.setType(1);
                            incomeRecordMember2.setAmount(Double.parseDouble(df.format(twoMoney.doubleValue())));
                            incomeRecordMember2.setMoney(Double.parseDouble(df.format(twoMoney.doubleValue())));
                            incomeRecordMember2.setUserId(two);
                            incomeRecordMember2.setFromUserId(member.getId());
                            incomeRecordMember2.setCreateTime(new Date());
                            save(incomeRecordMember2);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		two,
                            		Double.parseDouble(df.format(twoMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_pro));
                        } else {
                            moreMoney = moreMoney.add(twoMoney);
                        }

                        // 判断是否成为分销商
                        Member member3 = memberService.getById(one);
                        if (member3.getIsView() == 1) {
                            IncomeRecord incomeRecordMember3 = new IncomeRecord();
                            incomeRecordMember3.setObjId(orderId);// 设置订单ID
                            incomeRecordMember3.setObjType(1);// 收益类型是会员分红
                            incomeRecordMember3.setType(1);
                            incomeRecordMember3.setAmount(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember3.setMoney(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember3.setUserId(one);
                            incomeRecordMember3.setFromUserId(member.getId());
                            incomeRecordMember3.setCreateTime(new Date());
                            save(incomeRecordMember3);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		one,
                            		Double.parseDouble(df.format(oneMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_pro));
                        } else {
                            moreMoney = moreMoney.add(oneMoney);
                        }
                    }
                } else if(member.getType() == 4) {
                    // 平台的提成
                    IncomeRecord incomeRecordShop = new IncomeRecord();
                    incomeRecordShop.setObjId(orderId);
                    incomeRecordShop.setObjType(1);
                    incomeRecordShop.setType(1);
                    incomeRecordShop.setAmount(Double.parseDouble(df.format(adminMoney.doubleValue())));
                    incomeRecordShop.setMoney(Double.parseDouble(df.format(adminMoney.doubleValue())));
                    incomeRecordShop.setUserId(0L);// 分红的获得者
                    incomeRecordShop.setFromUserId(member.getId());
                    incomeRecordShop.setCreateTime(new Date());
                    save(incomeRecordShop);
                    adminRecordService.insert(new AdminAmountRecord(0l, 
                    		AdminAmountRecord.objType_admin,
                    		AdminAmountRecord.tradeType_commission, 
                    		Double.parseDouble(df.format(adminMoney.doubleValue())), 
                    		0d,
                    		orderId,
                    		OrderConstant.orderType_pro,
                    		Double.valueOf(order.getTotalMoney()), 
                    		Double.valueOf(totalScale)));
                    //运营中心的提成
                    IncomeRecord incomeRecordShopAchie = new IncomeRecord();
                    incomeRecordShopAchie.setObjId(orderId);
                    incomeRecordShopAchie.setObjType(1);
                    incomeRecordShopAchie.setType(1);
                    incomeRecordShopAchie.setAmount(Double.parseDouble(df.format(centerMoney.doubleValue())));
                    incomeRecordShopAchie.setMoney(Double.parseDouble(df.format(centerMoney.doubleValue())));
                    incomeRecordShopAchie.setUserId(center.getSelfMemberId());// 分红的获得者
                    incomeRecordShopAchie.setFromUserId(member.getId());
                    incomeRecordShopAchie.setCreateTime(new Date());
                    save(incomeRecordShopAchie);
                    adminRecordService.insert(new AdminAmountRecord(center.getId(), 
                    		AdminAmountRecord.objType_center,
                    		AdminAmountRecord.tradeType_commission, 
                    		Double.parseDouble(df.format(centerMoney.doubleValue())), 
                    		0d,
                    		orderId,
                    		OrderConstant.orderType_pro,
                    		Double.valueOf(order.getTotalMoney()), 
                    		Double.valueOf(totalScale)));
                    moreMoney = moreMoney.add(sellerMoney);
                    if (paths.length == 4) {
                        // 判断是否成为分销商
                        Member member1 = memberService.getById(Long.valueOf(paths[2]));
                        if (member1.getIsView() == 1) {
                            IncomeRecord incomeRecordMember1 = new IncomeRecord();
                            incomeRecordMember1.setObjId(orderId);// 设置订单ID
                            incomeRecordMember1.setObjType(1);// 收益类型是会员分红
                            incomeRecordMember1.setType(1);
                            incomeRecordMember1.setAmount(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember1.setMoney(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember1.setUserId(member1.getId());
                            incomeRecordMember1.setFromUserId(member.getId());
                            incomeRecordMember1.setCreateTime(new Date());
                            save(incomeRecordMember1);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		member1.getId(),
                            		Double.parseDouble(df.format(oneMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_pro));
                            moreMoney = moreMoney.add(twoMoney).add(threeMoney);
                        } else {
                            moreMoney = moreMoney.add(oneMoney).add(twoMoney).add(threeMoney);
                        }
                    } else if (paths.length == 5) {
                        // 判断是否成为分销商
                        Member member1 = memberService.getById(Long.valueOf(paths[2]));
                        if (member1.getIsView() == 1) {
                            IncomeRecord incomeRecordMember1 = new IncomeRecord();
                            incomeRecordMember1.setObjId(orderId);// 设置订单ID
                            incomeRecordMember1.setObjType(1);// 收益类型是会员分红
                            incomeRecordMember1.setType(1);
                            incomeRecordMember1.setAmount(Double.parseDouble(df.format(twoMoney.doubleValue())));
                            incomeRecordMember1.setMoney(Double.parseDouble(df.format(twoMoney.doubleValue())));
                            incomeRecordMember1.setUserId(member1.getId());
                            incomeRecordMember1.setFromUserId(member.getId());
                            incomeRecordMember1.setCreateTime(new Date());
                            save(incomeRecordMember1);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		member1.getId(),
                            		Double.parseDouble(df.format(twoMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_pro));
                        } else {
                            moreMoney = moreMoney.add(twoMoney);
                        }

                        // 判断是否成为分销商
                        Member member2 = memberService.getById(Long.valueOf(paths[3]));
                        if (member2.getIsView() == 1) {
                            IncomeRecord incomeRecordMember2 = new IncomeRecord();
                            incomeRecordMember2.setObjId(orderId);// 设置订单ID
                            incomeRecordMember2.setObjType(1);// 收益类型是会员分红
                            incomeRecordMember2.setType(1);
                            incomeRecordMember2.setAmount(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember2.setMoney(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember2.setUserId(member2.getId());
                            incomeRecordMember2.setFromUserId(member.getId());
                            incomeRecordMember2.setCreateTime(new Date());
                            save(incomeRecordMember2);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		member2.getId(),
                            		Double.parseDouble(df.format(oneMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_pro));
                        } else {
                            moreMoney = moreMoney.add(oneMoney);
                        }
                        moreMoney = moreMoney.add(threeMoney);
                    } else if (paths.length > 5) {
                        Long one = Long.valueOf(paths[paths.length - 2]);
                        Long two = Long.valueOf(paths[paths.length - 3]);
                        Long three = Long.valueOf(paths[paths.length - 4]);
                        // 判断是否成为分销商
                        Member member1 = memberService.getById(three);
                        if (member1.getIsView() == 1) {
                            IncomeRecord incomeRecordMember1 = new IncomeRecord();
                            incomeRecordMember1.setObjId(orderId);// 设置订单ID
                            incomeRecordMember1.setObjType(1);// 收益类型是会员分红
                            incomeRecordMember1.setType(1);
                            incomeRecordMember1.setAmount(Double.parseDouble(df.format(threeMoney.doubleValue())));
                            incomeRecordMember1.setMoney(Double.parseDouble(df.format(threeMoney.doubleValue())));
                            incomeRecordMember1.setUserId(three);
                            incomeRecordMember1.setFromUserId(member.getId());
                            incomeRecordMember1.setCreateTime(new Date());
                            save(incomeRecordMember1);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		three,
                            		Double.parseDouble(df.format(threeMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_pro));
                        } else {
                            moreMoney = moreMoney.add(threeMoney);
                        }

                        // 判断是否成为分销商
                        Member member2 = memberService.getById(two);
                        if (member2.getIsView() == 1) {
                            IncomeRecord incomeRecordMember2 = new IncomeRecord();
                            incomeRecordMember2.setObjId(orderId);// 设置订单ID
                            incomeRecordMember2.setObjType(1);// 收益类型是会员分红
                            incomeRecordMember2.setType(1);
                            incomeRecordMember2.setAmount(Double.parseDouble(df.format(twoMoney.doubleValue())));
                            incomeRecordMember2.setMoney(Double.parseDouble(df.format(twoMoney.doubleValue())));
                            incomeRecordMember2.setUserId(two);
                            incomeRecordMember2.setFromUserId(member.getId());
                            incomeRecordMember2.setCreateTime(new Date());
                            save(incomeRecordMember2);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		two,
                            		Double.parseDouble(df.format(twoMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_pro));
                        } else {
                            moreMoney = moreMoney.add(twoMoney);
                        }

                        // 判断是否成为分销商
                        Member member3 = memberService.getById(one);
                        if (member3.getIsView() == 1) {
                            IncomeRecord incomeRecordMember3 = new IncomeRecord();
                            incomeRecordMember3.setObjId(orderId);// 设置订单ID
                            incomeRecordMember3.setObjType(1);// 收益类型是会员分红
                            incomeRecordMember3.setType(1);
                            incomeRecordMember3.setAmount(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember3.setMoney(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember3.setUserId(one);
                            incomeRecordMember3.setFromUserId(member.getId());
                            incomeRecordMember3.setCreateTime(new Date());
                            save(incomeRecordMember3);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		one,
                            		Double.parseDouble(df.format(oneMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_pro));
                        } else {
                            moreMoney = moreMoney.add(oneMoney);
                        }
                    }
                }
                //没分完全给平台
                IncomeRecord incomeRecordMember3 = new IncomeRecord();
                incomeRecordMember3.setObjId(orderId);// 设置订单ID
                incomeRecordMember3.setObjType(1);// 收益类型是会员分红
                incomeRecordMember3.setType(1);
                incomeRecordMember3.setAmount(Double.parseDouble(df.format(moreMoney.doubleValue())));
                incomeRecordMember3.setMoney(Double.parseDouble(df.format(moreMoney.doubleValue())));
                incomeRecordMember3.setUserId(0L);
                incomeRecordMember3.setFromUserId(member.getId());
                incomeRecordMember3.setCreateTime(new Date());
                save(incomeRecordMember3);
                adminRecordService.insert(new AdminAmountRecord(0l, 
                		AdminAmountRecord.objType_admin,
                		AdminAmountRecord.tradeType_commission, 
                		Double.parseDouble(df.format(moreMoney.doubleValue())), 
                		0d,
                		orderId, 
                		OrderConstant.orderType_pro,
                		Double.valueOf(order.getTotalMoney()), 
                		Double.valueOf(totalScale)));
            }
        }
//    }


    public void startIncomeTicket(Long orderId) {
        // 获取分红百分比
        CommissionConfig commission = commissionConfigService.getConfig();
        double adminSc = commission.getAdminLevel(); //总平台佣金
        double sellerSc = commission.getSellerLevel(); // 店铺佣金
        double centerSc = commission.getCenterLevel(); // 运营中心佣金
        double oneSc = commission.getFirstLevel(); // 一级会员佣金
        double twoSc = commission.getSecondLevel(); // 二级会员佣金
        double threeSc = commission.getThirdLevel(); // 三级会员佣金
        double moreSc = 1 - commission.getAdminLevel() - commission.getSellerLevel() - commission.getCenterLevel() - commission.getFirstLevel() - commission.getThirdLevel() - commission.getSecondLevel();
        TicketOrder order = ticketOrderService.getById(orderId);
        adminRecordService.insert(new AdminAmountRecord(order.getSellerId(), 
        		AdminAmountRecord.objType_seller,
        		AdminAmountRecord.tradeType_order, 
        		Double.valueOf(order.getWithAmount()), 
        		0d,
        		order.getId(), 
        		OrderConstant.orderType_ser,
        		Double.valueOf(order.getTotalMoney()), 
        		Double.valueOf(order.getTotalMoney()-order.getWithAmount())));
        Member member = memberService.getById(order.getMemberId());
        Seller seller = sellerService.getById(member.getSellerId());
        BusinessCenter center = businessCenterService.getById(member.getCenterId());

        DecimalFormat df = new DecimalFormat("0.00");
        List<TicketOrderItem> orderItems = ticketOrderItemService.findByField("orderId", orderId);
        int totalScale=0;
        for (TicketOrderItem oi : orderItems) {
            if (oi.getScale() == 0) {
                continue;
            } else {
            	totalScale+=oi.getScale()*oi.getNum();
            }
            if (totalScale>0) {
//              Double totalScale = oi.getScale() * oi.getNum() / 100.0;
                BigDecimal adminMoney = new BigDecimal(totalScale * adminSc);// 平台佣金
                BigDecimal centerMoney = new BigDecimal(totalScale * centerSc);// 运营中心佣金
                BigDecimal sellerMoney = new BigDecimal(totalScale * sellerSc);// 店铺佣金
                BigDecimal oneMoney = new BigDecimal(totalScale * oneSc);// 一级提成
                BigDecimal twoMoney = new BigDecimal(totalScale * twoSc);// 二级提成
                BigDecimal threeMoney = new BigDecimal(totalScale * threeSc);// 三级提成
                BigDecimal moreMoney = new BigDecimal(totalScale * moreSc);// 没分完
                String[] paths = member.getPath().split("/");// 会员路径的分割
                if (member.getType() == 3) {// 店铺发展的下线
                    // 平台的提成
                    IncomeRecord incomeRecordShop = new IncomeRecord();
                    incomeRecordShop.setObjId(orderId);
                    incomeRecordShop.setObjType(2);
                    incomeRecordShop.setType(1);
                    incomeRecordShop.setAmount(Double.parseDouble(df.format(adminMoney.doubleValue())));
                    incomeRecordShop.setMoney(Double.parseDouble(df.format(adminMoney.doubleValue())));
                    incomeRecordShop.setUserId(0L);// 分红的获得者
                    incomeRecordShop.setFromUserId(member.getId());
                    incomeRecordShop.setCreateTime(new Date());
                    save(incomeRecordShop);
                    AdminAmountRecord record=new AdminAmountRecord(0l, 
                    		AdminAmountRecord.objType_admin,
                    		AdminAmountRecord.tradeType_commission, 
                    		adminMoney.doubleValue(), 
                    		0d,
                    		orderId, 
                    		OrderConstant.orderType_ser,
                    		Double.valueOf(order.getTotalMoney()), 
                    		Double.valueOf(totalScale));
                    adminRecordService.insert(record);
                    //运营中心的提成
                    IncomeRecord incomeRecordShopAchie = new IncomeRecord();
                    incomeRecordShopAchie.setObjId(orderId);
                    incomeRecordShopAchie.setObjType(2);
                    incomeRecordShopAchie.setType(1);
                    incomeRecordShopAchie.setAmount(Double.parseDouble(df.format(centerMoney.doubleValue())));
                    incomeRecordShopAchie.setMoney(Double.parseDouble(df.format(centerMoney.doubleValue())));
                    incomeRecordShopAchie.setUserId(center.getSelfMemberId());// 分红的获得者
                    incomeRecordShopAchie.setFromUserId(member.getId());
                    incomeRecordShopAchie.setCreateTime(new Date());
                    save(incomeRecordShopAchie);
                    adminRecordService.insert(new AdminAmountRecord(member.getCenterId(), 
                    		AdminAmountRecord.objType_center,
                    		AdminAmountRecord.tradeType_commission, 
                    		Double.parseDouble(df.format(centerMoney.doubleValue())), 
                    		0d,
                    		orderId, 
                    		OrderConstant.orderType_ser,
                    		Double.valueOf(order.getTotalMoney()), 
                    		Double.valueOf(totalScale)));
                    //店铺的提成
                    IncomeRecord incomeRecordCha = new IncomeRecord();
                    incomeRecordCha.setObjId(orderId);
                    incomeRecordCha.setObjType(2);
                    incomeRecordCha.setType(1);
                    incomeRecordCha.setAmount(Double.parseDouble(df.format(sellerMoney.doubleValue())));
                    incomeRecordCha.setMoney(Double.parseDouble(df.format(sellerMoney.doubleValue())));
                    incomeRecordCha.setUserId(seller.getSelfMemberId());// 分红的获得者
                    incomeRecordCha.setFromUserId(member.getId());
                    incomeRecordCha.setCreateTime(new Date());
                    save(incomeRecordCha);
                    adminRecordService.insert(new AdminAmountRecord(member.getSellerId(), 
                    		AdminAmountRecord.objType_seller,
                    		AdminAmountRecord.tradeType_commission, 
                    		Double.parseDouble(df.format(sellerMoney.doubleValue())), 
                    		0d,
                    		orderId, 
                    		OrderConstant.orderType_ser,
                    		Double.valueOf(order.getTotalMoney()), 
                    		Double.valueOf(totalScale)));
                    if (paths.length == 5) {
                        // 判断是否成为分销商
                        Member member1 = memberService.getById(Long.valueOf(paths[3]));
                        if (member1.getIsView() == 1) {
                            IncomeRecord incomeRecordMember1 = new IncomeRecord();
                            incomeRecordMember1.setObjId(orderId);// 设置订单ID
                            incomeRecordMember1.setObjType(2);// 收益类型是会员分红
                            incomeRecordMember1.setType(1);
                            incomeRecordMember1.setAmount(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember1.setMoney(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember1.setUserId(member1.getId());
                            incomeRecordMember1.setFromUserId(member.getId());
                            incomeRecordMember1.setCreateTime(new Date());
                           
                            save(incomeRecordMember1);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		member1.getId(),
                            		Double.parseDouble(df.format(oneMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_ser));
                            moreMoney = moreMoney.add(twoMoney).add(threeMoney);
                        } else {
                            moreMoney = moreMoney.add(oneMoney).add(twoMoney).add(threeMoney);
                        }
                    } else if (paths.length == 6) {
                        // 判断是否成为分销商
                        Member member1 = memberService.getById(Long.valueOf(paths[3]));
                        if (member1.getIsView() == 1) {
                            IncomeRecord incomeRecordMember1 = new IncomeRecord();
                            incomeRecordMember1.setObjId(orderId);// 设置订单ID
                            incomeRecordMember1.setObjType(2);// 收益类型是会员分红
                            incomeRecordMember1.setType(1);
                            incomeRecordMember1.setAmount(Double.parseDouble(df.format(twoMoney.doubleValue())));
                            incomeRecordMember1.setMoney(Double.parseDouble(df.format(twoMoney.doubleValue())));
                            incomeRecordMember1.setUserId(member1.getId());
                            incomeRecordMember1.setFromUserId(member.getId());
                            incomeRecordMember1.setCreateTime(new Date());
                            save(incomeRecordMember1);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		member1.getId(),
                            		Double.parseDouble(df.format(twoMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_ser));
                        } else {
                            moreMoney = moreMoney.add(twoMoney);
                        }

                        // 判断是否成为分销商
                        Member member2 = memberService.getById(Long.valueOf(paths[4]));
                        if (member2.getIsView() == 1) {
                            IncomeRecord incomeRecordMember2 = new IncomeRecord();
                            incomeRecordMember2.setObjId(orderId);// 设置订单ID
                            incomeRecordMember2.setObjType(2);// 收益类型是会员分红
                            incomeRecordMember2.setType(1);
                            incomeRecordMember2.setAmount(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember2.setMoney(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember2.setUserId(member2.getId());
                            incomeRecordMember2.setFromUserId(member.getId());
                            incomeRecordMember2.setCreateTime(new Date());
                            save(incomeRecordMember2);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		member2.getId(),
                            		Double.parseDouble(df.format(oneMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_ser));
                        } else {
                            moreMoney = moreMoney.add(oneMoney);
                        }
                        moreMoney = moreMoney.add(threeMoney);
                    } else if (paths.length > 6) {
                        Long one = Long.valueOf(paths[paths.length - 2]);
                        Long two = Long.valueOf(paths[paths.length - 3]);
                        Long three = Long.valueOf(paths[paths.length - 4]);
                        // 判断是否成为分销商
                        Member member1 = memberService.getById(three);
                        if (member1.getIsView() == 1) {
                            IncomeRecord incomeRecordMember1 = new IncomeRecord();
                            incomeRecordMember1.setObjId(orderId);// 设置订单ID
                            incomeRecordMember1.setObjType(2);// 收益类型是会员分红
                            incomeRecordMember1.setType(1);
                            incomeRecordMember1.setAmount(Double.parseDouble(df.format(threeMoney.doubleValue())));
                            incomeRecordMember1.setMoney(Double.parseDouble(df.format(threeMoney.doubleValue())));
                            incomeRecordMember1.setUserId(three);
                            incomeRecordMember1.setFromUserId(member.getId());
                            incomeRecordMember1.setCreateTime(new Date());
                            save(incomeRecordMember1);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		three,
                            		Double.parseDouble(df.format(threeMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_ser));
                        } else {
                            moreMoney = moreMoney.add(threeMoney);
                        }

                        // 判断是否成为分销商
                        Member member2 = memberService.getById(two);
                        if (member2.getIsView() == 1) {
                            IncomeRecord incomeRecordMember2 = new IncomeRecord();
                            incomeRecordMember2.setObjId(orderId);// 设置订单ID
                            incomeRecordMember2.setObjType(2);// 收益类型是会员分红
                            incomeRecordMember2.setType(1);
                            incomeRecordMember2.setAmount(Double.parseDouble(df.format(twoMoney.doubleValue())));
                            incomeRecordMember2.setMoney(Double.parseDouble(df.format(twoMoney.doubleValue())));
                            incomeRecordMember2.setUserId(two);
                            incomeRecordMember2.setFromUserId(member.getId());
                            incomeRecordMember2.setCreateTime(new Date());
                            save(incomeRecordMember2);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		two,
                            		Double.parseDouble(df.format(twoMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_ser));
                        } else {
                            moreMoney = moreMoney.add(twoMoney);
                        }

                        // 判断是否成为分销商
                        Member member3 = memberService.getById(one);
                        if (member3.getIsView() == 1) {
                            IncomeRecord incomeRecordMember3 = new IncomeRecord();
                            incomeRecordMember3.setObjId(orderId);// 设置订单ID
                            incomeRecordMember3.setObjType(2);// 收益类型是会员分红
                            incomeRecordMember3.setType(1);
                            incomeRecordMember3.setAmount(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember3.setMoney(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember3.setUserId(one);
                            incomeRecordMember3.setFromUserId(member.getId());
                            incomeRecordMember3.setCreateTime(new Date());
                            save(incomeRecordMember3);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		one,
                            		Double.parseDouble(df.format(oneMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_ser));
                        } else {
                            moreMoney = moreMoney.add(oneMoney);
                        }
                    }
                } else if(member.getType() == 4) {
                    // 平台的提成
                    IncomeRecord incomeRecordShop = new IncomeRecord();
                    incomeRecordShop.setObjId(orderId);
                    incomeRecordShop.setObjType(2);
                    incomeRecordShop.setType(1);
                    incomeRecordShop.setAmount(Double.parseDouble(df.format(adminMoney.doubleValue())));
                    incomeRecordShop.setMoney(Double.parseDouble(df.format(adminMoney.doubleValue())));
                    incomeRecordShop.setUserId(0L);// 分红的获得者
                    incomeRecordShop.setFromUserId(member.getId());
                    incomeRecordShop.setCreateTime(new Date());
                    save(incomeRecordShop);
                    adminRecordService.insert(new AdminAmountRecord(0l, 
                    		AdminAmountRecord.objType_admin,
                    		AdminAmountRecord.tradeType_commission, 
                    		Double.parseDouble(df.format(adminMoney.doubleValue())), 
                    		0d,
                    		orderId, 
                    		OrderConstant.orderType_ser,
                    		Double.valueOf(order.getTotalMoney()), 
                    		Double.valueOf(totalScale)));
                    //运营中心的提成
                    IncomeRecord incomeRecordShopAchie = new IncomeRecord();
                    incomeRecordShopAchie.setObjId(orderId);
                    incomeRecordShopAchie.setObjType(2);
                    incomeRecordShopAchie.setType(1);
                    incomeRecordShopAchie.setAmount(Double.parseDouble(df.format(centerMoney.doubleValue())));
                    incomeRecordShopAchie.setMoney(Double.parseDouble(df.format(centerMoney.doubleValue())));
                    incomeRecordShopAchie.setUserId(center.getSelfMemberId());// 分红的获得者
                    incomeRecordShopAchie.setFromUserId(member.getId());
                    incomeRecordShopAchie.setCreateTime(new Date());
                    save(incomeRecordShopAchie);
                    adminRecordService.insert(new AdminAmountRecord(center.getId(), 
                    		AdminAmountRecord.objType_center,
                    		AdminAmountRecord.tradeType_commission, 
                    		Double.parseDouble(df.format(centerMoney.doubleValue())), 
                    		0d,
                    		orderId, 
                    		OrderConstant.orderType_ser,
                    		Double.valueOf(order.getTotalMoney()), 
                    		Double.valueOf(totalScale)));
                    moreMoney = moreMoney.add(sellerMoney);
                    if (paths.length == 4) {
                        // 判断是否成为分销商
                        Member member1 = memberService.getById(Long.valueOf(paths[2]));
                        if (member1.getIsView() == 1) {
                            IncomeRecord incomeRecordMember1 = new IncomeRecord();
                            incomeRecordMember1.setObjId(orderId);// 设置订单ID
                            incomeRecordMember1.setObjType(2);// 收益类型是会员分红
                            incomeRecordMember1.setType(1);
                            incomeRecordMember1.setAmount(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember1.setMoney(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember1.setUserId(member1.getId());
                            incomeRecordMember1.setFromUserId(member.getId());
                            incomeRecordMember1.setCreateTime(new Date());
                            save(incomeRecordMember1);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		member1.getId(),
                            		Double.parseDouble(df.format(oneMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_ser));
                            moreMoney = moreMoney.add(twoMoney).add(threeMoney);
                        } else {
                            moreMoney = moreMoney.add(oneMoney).add(twoMoney).add(threeMoney);
                        }
                    } else if (paths.length == 5) {
                        // 判断是否成为分销商
                        Member member1 = memberService.getById(Long.valueOf(paths[2]));
                        if (member1.getIsView() == 1) {
                            IncomeRecord incomeRecordMember1 = new IncomeRecord();
                            incomeRecordMember1.setObjId(orderId);// 设置订单ID
                            incomeRecordMember1.setObjType(2);// 收益类型是会员分红
                            incomeRecordMember1.setType(1);
                            incomeRecordMember1.setAmount(Double.parseDouble(df.format(twoMoney.doubleValue())));
                            incomeRecordMember1.setMoney(Double.parseDouble(df.format(twoMoney.doubleValue())));
                            incomeRecordMember1.setUserId(member1.getId());
                            incomeRecordMember1.setFromUserId(member.getId());
                            incomeRecordMember1.setCreateTime(new Date());
                            save(incomeRecordMember1);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		member1.getId(),
                            		Double.parseDouble(df.format(twoMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_ser));
                        } else {
                            moreMoney = moreMoney.add(twoMoney);
                        }

                        // 判断是否成为分销商
                        Member member2 = memberService.getById(Long.valueOf(paths[3]));
                        if (member2.getIsView() == 1) {
                            IncomeRecord incomeRecordMember2 = new IncomeRecord();
                            incomeRecordMember2.setObjId(orderId);// 设置订单ID
                            incomeRecordMember2.setObjType(2);// 收益类型是会员分红
                            incomeRecordMember2.setType(1);
                            incomeRecordMember2.setAmount(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember2.setMoney(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember2.setUserId(member2.getId());
                            incomeRecordMember2.setFromUserId(member.getId());
                            incomeRecordMember2.setCreateTime(new Date());
                            save(incomeRecordMember2);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		member2.getId(),
                            		Double.parseDouble(df.format(oneMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_ser));
                        } else {
                            moreMoney = moreMoney.add(oneMoney);
                        }
                        moreMoney = moreMoney.add(threeMoney);
                    } else if (paths.length > 5) {
                        Long one = Long.valueOf(paths[paths.length - 2]);
                        Long two = Long.valueOf(paths[paths.length - 3]);
                        Long three = Long.valueOf(paths[paths.length - 4]);
                        // 判断是否成为分销商
                        Member member1 = memberService.getById(three);
                        if (member1.getIsView() == 1) {
                            IncomeRecord incomeRecordMember1 = new IncomeRecord();
                            incomeRecordMember1.setObjId(orderId);// 设置订单ID
                            incomeRecordMember1.setObjType(2);// 收益类型是会员分红
                            incomeRecordMember1.setType(1);
                            incomeRecordMember1.setAmount(Double.parseDouble(df.format(threeMoney.doubleValue())));
                            incomeRecordMember1.setMoney(Double.parseDouble(df.format(threeMoney.doubleValue())));
                            incomeRecordMember1.setUserId(three);
                            incomeRecordMember1.setFromUserId(member.getId());
                            incomeRecordMember1.setCreateTime(new Date());
                            save(incomeRecordMember1);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		three,
                            		Double.parseDouble(df.format(threeMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_ser));
                        } else {
                            moreMoney = moreMoney.add(threeMoney);
                        }

                        // 判断是否成为分销商
                        Member member2 = memberService.getById(two);
                        if (member2.getIsView() == 1) {
                            IncomeRecord incomeRecordMember2 = new IncomeRecord();
                            incomeRecordMember2.setObjId(orderId);// 设置订单ID
                            incomeRecordMember2.setObjType(2);// 收益类型是会员分红
                            incomeRecordMember2.setType(1);
                            incomeRecordMember2.setAmount(Double.parseDouble(df.format(twoMoney.doubleValue())));
                            incomeRecordMember2.setMoney(Double.parseDouble(df.format(twoMoney.doubleValue())));
                            incomeRecordMember2.setUserId(two);
                            incomeRecordMember2.setFromUserId(member.getId());
                            incomeRecordMember2.setCreateTime(new Date());
                            save(incomeRecordMember2);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		two,
                            		Double.parseDouble(df.format(twoMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_ser));
                        } else {
                            moreMoney = moreMoney.add(twoMoney);
                        }

                        // 判断是否成为分销商
                        Member member3 = memberService.getById(one);
                        if (member3.getIsView() == 1) {
                            IncomeRecord incomeRecordMember3 = new IncomeRecord();
                            incomeRecordMember3.setObjId(orderId);// 设置订单ID
                            incomeRecordMember3.setObjType(2);// 收益类型是会员分红
                            incomeRecordMember3.setType(1);
                            incomeRecordMember3.setAmount(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember3.setMoney(Double.parseDouble(df.format(oneMoney.doubleValue())));
                            incomeRecordMember3.setUserId(one);
                            incomeRecordMember3.setFromUserId(member.getId());
                            incomeRecordMember3.setCreateTime(new Date());
                            save(incomeRecordMember3);
                            withdrawRecordService.insert(new UserWithdrawRecord(
                            		one,
                            		Double.parseDouble(df.format(oneMoney.doubleValue())),
                            		0d,
                            		orderId,
                            		OrderConstant.orderType_ser));
                        } else {
                            moreMoney = moreMoney.add(oneMoney);
                        }
                    }
                }
                //没分完全给平台
                IncomeRecord incomeRecordMember3 = new IncomeRecord();
                incomeRecordMember3.setObjId(orderId);// 设置订单ID
                incomeRecordMember3.setObjType(2);// 收益类型是会员分红
                incomeRecordMember3.setType(1);
                incomeRecordMember3.setAmount(Double.parseDouble(df.format(moreMoney.doubleValue())));
                incomeRecordMember3.setMoney(Double.parseDouble(df.format(moreMoney.doubleValue())));
                incomeRecordMember3.setUserId(0L);
                incomeRecordMember3.setFromUserId(member.getId());
                incomeRecordMember3.setCreateTime(new Date());
                save(incomeRecordMember3);
                adminRecordService.insert(new AdminAmountRecord(0l, 
                		AdminAmountRecord.objType_admin,
                		AdminAmountRecord.tradeType_commission, 
                		Double.parseDouble(df.format(moreMoney.doubleValue())), 
                		0d,
                		orderId, 
                		OrderConstant.orderType_ser,
                		Double.valueOf(order.getTotalMoney()), 
                		Double.valueOf(totalScale)));
            }
        }
    }
}
